<template>
  <div class="pop-dialog-container">
    <div class="pop-dialog-main">
      <el-form label-position="right" :model="salaryForm" :label-width="formLabelWidth" disabled="disabled">
        <el-row>
          <el-col :span="11">
            <el-form-item label="员工姓名">
              <el-input v-model="salaryForm.employeeName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="基本工资">
              <el-input v-model="salaryForm.basicSalary"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="绩效工资">
              <el-input v-model="salaryForm.performanceSalary"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="奖金">
              <el-input v-model="salaryForm.bonus"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="津贴">
              <el-input v-model="salaryForm.allowance"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="加班费">
              <el-input v-model="salaryForm.overtimePay"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="社保扣除">
              <el-input v-model="salaryForm.socialSecurityDeduction"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="公积金扣除">
              <el-input v-model="salaryForm.housingFundDeduction"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="个人所得税扣除">
              <el-input v-model="salaryForm.personalIncomeTaxDeduction"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="其他扣除">
              <el-input v-model="salaryForm.otherDeductions"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="应发工资">
              <el-input v-model="salaryForm.grossSalary"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="实发工资">
              <el-input v-model="salaryForm.netSalary"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="发放日期">
              <el-input v-model="salaryForm.payDate"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="支付方式">
              <el-select v-model="salaryForm.paymentMethod" placeholder="请选择支付方式">
                <el-option label="银行转账" :value="10"></el-option>
                <el-option label="现金" :value="20"></el-option>
                <el-option label="支票" :value="30"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="银行账号">
              <el-input v-model="salaryForm.bankAccountNumber"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="创建时间">
              <el-input v-model="salaryForm.createTime"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="最后修改时间">
              <el-input v-model="salaryForm.modifyTime"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="pop-dialog-footer">
      <el-row>
        <el-col :span="12" :offset="6">
          <div class="form-button-container">
            <el-button @click="onBack" type="primary">关闭</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup lang="ts">
import {defineEmits, defineProps, onMounted, reactive, ref, inject, toRefs} from 'vue';
import salaryApi from '@/api/salaryApi'
import type {Salary} from "@/types/resp/salary";
import type {Id} from "@/types/id"

const salaryForm = reactive<Partial<Salary>>({});
const props = defineProps<Id>()
const emit = defineEmits<{
  (e: 'closeSalaryViewEvent'): void;
}>()
const formLabelWidth = ref<string>('')

onMounted(() => {
  initSalaryById(props.id)
  const globalState = inject('globalState', {} as { formLabelWidth?: string })
  if (!globalState) {
    throw new Error('globalState is not provided');
  }
  const globalStateRefs = toRefs(globalState)
  if (globalStateRefs.formLabelWidth) {
    formLabelWidth.value = globalStateRefs.formLabelWidth.value || ''
  }
})

const initSalaryById = async (id: number) => {
  const resp = await salaryApi.findById(id)
  if (resp && resp.code === 1 && resp.data) {
    Object.assign(salaryForm, resp.data)
  }
}
const onBack = () => {
  emit('closeSalaryViewEvent')
}
</script>

<style lang="scss">
</style>